package cn.xzc.job.cocurrent;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;

class DelegatingCompletableFuture<T> extends CompletableFuture<T> {
    private final Future<T> delegate;

    public DelegatingCompletableFuture(Future<T> delegate) {
        this.delegate = delegate;
    }

    /**
     * 取消异步任务执行
     *
     * @param mayInterruptIfRunning 是否立即执行
     * @return 任务是否被成功取消
     */
    @Override
    public boolean cancel(boolean mayInterruptIfRunning) {
        boolean result = this.delegate.cancel(mayInterruptIfRunning);
        super.cancel(mayInterruptIfRunning);
        return result;
    }
}